<template>
  <div class="home-container">
    <!-- 导航栏 -->
    <van-nav-bar class="page-nav-bar" title="登录" fixed>
      <van-button
        class="search-btn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
      >搜索</van-button>
    </van-nav-bar>
    <!-- 频道列表导航 -->
    <!--
      animated 滑动的动画
      border 底边框线
      swipeable 开启左右手势滑动
    -->
    <van-tabs  class="channel-tabs" v-model="active" swipeable animated border>
      <!-- 循环频道列表 -->
      <van-tab v-for="channel in UserChannels" :key="channel.id">
        <div slot="title">
          {{ channel.name }}
        </div>
        <div slot="default">
          <ArticleList :channel="channel"></ArticleList>
        </div>
      </van-tab>
      <!-- 右侧自定义内容 -->
      <!-- 占位元素  slot插槽用法 -->
      <!-- 设置 flex-shrink: 0 不参与flex空间的运算 ,可以自己设置宽高 -->
      <div class="placeholder" slot="nav-right"></div>
      <!-- 右侧按钮 -->
      <!-- #nav-right 右侧插槽  插入字体图标 使用template会出现覆盖问题-->
      <!-- <template #nav-right>
        <div class="hamburger-btn">
          <i class="toutiao toutiao-gengduo"></i>
        </div>
      </template> -->
      <div class="hamburger-btn" slot="nav-right" @click="isShowPopup=true">
        <i class="toutiao toutiao-gengduo"></i>
      </div>
    </van-tabs>
    <van-popup v-model="isShowPopup" position="bottom" :style="{ height: '100%' }" closeable
    close-icon-position="top-left">
      <ChannelEdit :myChannel="UserChannels" :active="active" @changeActive="changeActive"></ChannelEdit>
    </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from '@/api/user'
import ArticleList from '@/views/home/components/article-list'
import ChannelEdit from '@/views/home/components/channel-edit'
export default {
  name: 'homeIndex',
  components: {
    ArticleList,
    ChannelEdit
  },
  props: {},
  data () {
    return {
      active: 0,
      UserChannels: [],
      isShowPopup: false
    }
  },
  computed: {},
  watch: {},
  created () {
    this.loadUserChannels()
  },
  mounted () {},
  methods: {
    async loadUserChannels () {
      try {
        const { data } = await getUserChannels()
        console.log(data)
        this.UserChannels = data.data.channels
      } catch (error) {
        this.$toast('获取频道列表失败!')
      }
    },
    changeActive (index, bool) {
      this.active = index
      this.isShowPopup = bool
    }
  }
}
</script>
<style lang='less' scoped>
.home-container {
  padding-top: 174px;
  padding-bottom: 100px;
  //  /deep/ 穿透选择器 搜索标签
  /deep/ .van-tabs__wrap {
    position: fixed;
    height: 82px;
    top: 92px;
    left: 0;
    right: 0;
    z-index: 1;
  }
  /deep/ .van-nav-bar__title {
    //  unset 为取消
    max-width: unset;
  }
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    .van-icon {
      font-size: 32px;
    }
  }
  //  频道导航
  /deep/ .channel-tabs {
    .van-tab {
      border-right: 1px solid #edeff3;
      min-width: 200px;
      font-size: 30px;
      color: #777777;
    }

    .van-tab--active {
      color: #333333;
    }

    .van-tabs__nav {
      padding-bottom: 0;
    }

    .van-tabs__line {
      bottom: 8px;
      width: 31px !important;
      height: 6px;
      background-color: #3296fa;
    }

    .placeholder {
      flex-shrink: 0;
      width: 66px;
      height: 82px;
    }

    .hamburger-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      background-color: rgba(255, 255, 255, 0.902);
      i.toutiao {
        font-size: 33px;
      }
      &:before {
        content: "";
        position: absolute;
        left: 0;
        width: 1px;
        height: 58px;
        background-image: url(~@/assets/gradient-gray-line.png);
        background-size: contain;
      }
    }
  }
}
</style>
